﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Setting
{
	/// <summary>
	/// Summary description for ErcAlmClrSet.
	/// </summary>
	public class ErcAlmClrSet : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button btnReturn;
		private System.Windows.Forms.CheckBox chkErc1;
		private System.Windows.Forms.CheckBox chkErc2;
		private System.Windows.Forms.ComboBox cboErcTime;
		private System.Windows.Forms.ComboBox cboErcOffTimer;
		private System.Windows.Forms.ComboBox cboAlmClrTime;
		private System.Windows.Forms.Label lblErc1;
		private System.Windows.Forms.Label lblErc2;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		/////////////////////////////////////////////////
		// SMC access function
		/////////////////////////////////////////////////
		public ErcAlmClrSet()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.lblErc2 = new System.Windows.Forms.Label();
			this.lblErc1 = new System.Windows.Forms.Label();
			this.chkErc2 = new System.Windows.Forms.CheckBox();
			this.chkErc1 = new System.Windows.Forms.CheckBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.cboErcTime = new System.Windows.Forms.ComboBox();
			this.cboErcOffTimer = new System.Windows.Forms.ComboBox();
			this.cboAlmClrTime = new System.Windows.Forms.ComboBox();
			this.btnReturn = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.lblErc2,
																					this.lblErc1,
																					this.chkErc2,
																					this.chkErc1});
			this.groupBox1.Location = new System.Drawing.Point(16, 16);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(360, 104);
			this.groupBox1.TabIndex = 2;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Counter Clear (ERC)";
			// 
			// lblErc2
			// 
			this.lblErc2.Location = new System.Drawing.Point(240, 62);
			this.lblErc2.Name = "lblErc2";
			this.lblErc2.Size = new System.Drawing.Size(112, 20);
			this.lblErc2.TabIndex = 8;
			this.lblErc2.Text = "Auto Out";
			// 
			// lblErc1
			// 
			this.lblErc1.Location = new System.Drawing.Point(240, 30);
			this.lblErc1.Name = "lblErc1";
			this.lblErc1.Size = new System.Drawing.Size(112, 20);
			this.lblErc1.TabIndex = 7;
			this.lblErc1.Text = "Auto Out";
			// 
			// chkErc2
			// 
			this.chkErc2.Location = new System.Drawing.Point(11, 56);
			this.chkErc2.Name = "chkErc2";
			this.chkErc2.Size = new System.Drawing.Size(192, 32);
			this.chkErc2.TabIndex = 4;
			this.chkErc2.Text = "ORG motion end :";
			this.chkErc2.CheckedChanged += new System.EventHandler(this.chkErc2_CheckedChanged);
			// 
			// chkErc1
			// 
			this.chkErc1.Location = new System.Drawing.Point(11, 24);
			this.chkErc1.Name = "chkErc1";
			this.chkErc1.Size = new System.Drawing.Size(192, 32);
			this.chkErc1.TabIndex = 3;
			this.chkErc1.Text = "Stop by EL and ALM input :";
			this.chkErc1.CheckedChanged += new System.EventHandler(this.chkErc1_CheckedChanged);
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(16, 140);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(119, 14);
			this.label1.TabIndex = 1;
			this.label1.Text = "Counter Clear Time :";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(16, 180);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(143, 14);
			this.label2.TabIndex = 2;
			this.label2.Text = "Counter Clear Off Timer :";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Location = new System.Drawing.Point(16, 220);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(107, 14);
			this.label3.TabIndex = 3;
			this.label3.Text = "Alarm Clear Time :";
			// 
			// cboErcTime
			// 
			this.cboErcTime.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboErcTime.Location = new System.Drawing.Point(168, 136);
			this.cboErcTime.Name = "cboErcTime";
			this.cboErcTime.Size = new System.Drawing.Size(208, 23);
			this.cboErcTime.TabIndex = 7;
			this.cboErcTime.SelectedIndexChanged += new System.EventHandler(this.cboErcTime_SelectedIndexChanged);
			// 
			// cboErcOffTimer
			// 
			this.cboErcOffTimer.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboErcOffTimer.Location = new System.Drawing.Point(168, 176);
			this.cboErcOffTimer.Name = "cboErcOffTimer";
			this.cboErcOffTimer.Size = new System.Drawing.Size(208, 23);
			this.cboErcOffTimer.TabIndex = 8;
			this.cboErcOffTimer.SelectedIndexChanged += new System.EventHandler(this.cboErcOffTimer_SelectedIndexChanged);
			// 
			// cboAlmClrTime
			// 
			this.cboAlmClrTime.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboAlmClrTime.Location = new System.Drawing.Point(168, 216);
			this.cboAlmClrTime.Name = "cboAlmClrTime";
			this.cboAlmClrTime.Size = new System.Drawing.Size(208, 23);
			this.cboAlmClrTime.TabIndex = 8;
			this.cboAlmClrTime.SelectedIndexChanged += new System.EventHandler(this.cboAlmClrTime_SelectedIndexChanged);
			// 
			// btnReturn
			// 
			this.btnReturn.Location = new System.Drawing.Point(256, 256);
			this.btnReturn.Name = "btnReturn";
			this.btnReturn.Size = new System.Drawing.Size(120, 32);
			this.btnReturn.TabIndex = 1;
			this.btnReturn.Text = "Return";
			this.btnReturn.Click += new System.EventHandler(this.btnReturn_Click);
			// 
			// ErcAlmClrSet
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(394, 302);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnReturn,
																		  this.cboAlmClrTime,
																		  this.cboErcOffTimer,
																		  this.cboErcTime,
																		  this.label3,
																		  this.label2,
																		  this.label1,
																		  this.groupBox1});
			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "ErcAlmClrSet";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "ERC/ALM Clear Setting";
			this.Load += new System.EventHandler(this.ErcAlmClrSet_Load);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnReturn_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void chkErc1_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit = 0x1;
			int	tmp = Setting.ErcMode;
			if( chkErc1.Checked == false )
			{
				lblErc1.Text = "Not Use";
				tmp = tmp & (~bit);
				Setting.ErcMode = (short)tmp;
			}
			else
			{
				lblErc1.Text = "Auto Out";
				tmp = tmp | bit;
				Setting.ErcMode = (short)tmp;
			}
		}

		private void chkErc2_CheckedChanged(object sender, System.EventArgs e)
		{
			int	bit =0x2;
			int	tmp = Setting.ErcMode;
			if( chkErc2.Checked == false )
			{
				lblErc2.Text = "Not Use";
				tmp = tmp & (~bit);
				Setting.ErcMode = (short)tmp;
			}
			else
			{
				lblErc2.Text = "Auto Out";
				tmp = tmp | bit;
				Setting.ErcMode = (short)tmp;
			}
		}

		private void cboErcTime_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Setting.ErcTime = (short)cboErcTime.SelectedIndex;
		}

		private void cboErcOffTimer_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Setting.ErcOffTimer = (short)cboErcOffTimer.SelectedIndex;
		}

		private void cboAlmClrTime_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Setting.AlmTime = (short)cboAlmClrTime.SelectedIndex;
		}

		private void ErcAlmClrSet_Load(object sender, System.EventArgs e)
		{
			cboErcTime.Enabled = false;
			cboErcOffTimer.Enabled = false;
			cboAlmClrTime.Enabled = false;
			if( Setting.CtrlOut1 == 2 || Setting.CtrlOut2 == 2 || Setting.CtrlOut3 == 2 )
			{
				cboErcTime.Enabled = true;
				cboErcOffTimer.Enabled = true;
			}
			if( Setting.CtrlOut1 == 1 || Setting.CtrlOut2 == 1 || Setting.CtrlOut3 == 1 )
			{
				cboAlmClrTime.Enabled = true;
			}
			// OUT1 ComboBox
			cboErcTime.Items.Clear();
			cboErcTime.Items.Add("12 [usec]");
			cboErcTime.Items.Add("102 [usec]");
			cboErcTime.Items.Add("408 [usec]");
			cboErcTime.Items.Add("1.6 [msec]");
			cboErcTime.Items.Add("13 [msec]");
			cboErcTime.Items.Add("52 [msec]");
			cboErcTime.Items.Add("104 [msec]");
			cboErcTime.Items.Add("Level");

			// OUT2 ComboBox
			cboErcOffTimer.Items.Clear();
			cboErcOffTimer.Items.Add("0 [usec]");
			cboErcOffTimer.Items.Add("12 [usec]");
			cboErcOffTimer.Items.Add("1.6 [msec]");
			cboErcOffTimer.Items.Add("104 [msec]");

			// OUT3 ComboBox
			cboAlmClrTime.Items.Clear();
			cboAlmClrTime.Items.Add("12 [usec]");
			cboAlmClrTime.Items.Add("102 [usec]");
			cboAlmClrTime.Items.Add("408 [msec]");
			cboAlmClrTime.Items.Add("1.6 [msec]");
			cboAlmClrTime.Items.Add("13 [msec]");
			cboAlmClrTime.Items.Add("52 [msec]");
			cboAlmClrTime.Items.Add("104 [msec]");

			// ComboBox Initialise
			cboErcTime.SelectedIndex = Setting.ErcTime;
			cboErcOffTimer.SelectedIndex = Setting.ErcOffTimer;
			cboAlmClrTime.SelectedIndex = Setting.AlmTime;

			// CheckBox Initialise
//			chkErc1.Checked = false;
			lblErc1.Text = "Not Use";
			if( (Setting.ErcMode & 0x1) != 0 )
			{
				chkErc1.Checked = true;
				lblErc1.Text = "Auto Out";
			}

//			chkErc2.Checked = false;
			lblErc2.Text = "Not Use";
			if( (Setting.ErcMode & 0x2) != 0 )
			{
				chkErc2.Checked = true;
				lblErc2.Text = "Auto Out";
			}
		}

	}
}
